# 统计字母出现的个数
from collections import defaultdict
d1 = defaultdict(lambda: 0)

string1 = "abcavaefegsgdghfdefavbdr"


def count(string: str):
    for number in string:
        d1[number] += 1
    return d1


def top(n=3):

    return sorted(d1.items(), key=lambda x: x[1], reverse=True)[:3]


print("1，字符串的出现次数统计：", count(string1))
print("2,出现次数最多的3个元素：", top())

# 用普通字典试试？